package com.ruoyi.web.controller.app;

import com.ruoyi.app.domain.AppScenicSpot;
import com.ruoyi.app.service.IAppScenicSpotService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 景点Controller
 *
 * @author ruoyi
 * @date 2025-01-12
 */
@RestController
@RequestMapping("/app/spot")
public class AppScenicSpotController extends BaseController
{
    @Autowired
    private IAppScenicSpotService appScenicSpotService;

    /**
     * 查询景点列表
     */
    @PreAuthorize("@ss.hasPermi('app:spot:list')")
    @GetMapping("/list")
    public TableDataInfo list(AppScenicSpot appScenicSpot)
    {
        startPage();
        List<AppScenicSpot> list = appScenicSpotService.selectAppScenicSpotList(appScenicSpot);
        return getDataTable(list);
    }

    /**
     * 导出景点列表
     */
    @PreAuthorize("@ss.hasPermi('app:spot:export')")
    @Log(title = "景点", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AppScenicSpot appScenicSpot)
    {
        List<AppScenicSpot> list = appScenicSpotService.selectAppScenicSpotList(appScenicSpot);
        ExcelUtil<AppScenicSpot> util = new ExcelUtil<AppScenicSpot>(AppScenicSpot.class);
        util.exportExcel(response, list, "景点数据");
    }

    /**
     * 获取景点详细信息
     */
    @PreAuthorize("@ss.hasPermi('app:spot:query')")
    @GetMapping(value = "/{spotId}")
    public AjaxResult getInfo(@PathVariable("spotId") Long spotId)
    {
        return success(appScenicSpotService.selectAppScenicSpotBySpotId(spotId));
    }

    /**
     * 新增景点
     */
    @PreAuthorize("@ss.hasPermi('app:spot:add')")
    @Log(title = "景点", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AppScenicSpot appScenicSpot)
    {
        return toAjax(appScenicSpotService.insertAppScenicSpot(appScenicSpot));
    }

    /**
     * 修改景点
     */
    @PreAuthorize("@ss.hasPermi('app:spot:edit')")
    @Log(title = "景点", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AppScenicSpot appScenicSpot)
    {
        return toAjax(appScenicSpotService.updateAppScenicSpot(appScenicSpot));
    }

    /**
     * 删除景点
     */
    @PreAuthorize("@ss.hasPermi('app:spot:remove')")
    @Log(title = "景点", businessType = BusinessType.DELETE)
	@DeleteMapping("/{spotIds}")
    public AjaxResult remove(@PathVariable Long[] spotIds)
    {
        return toAjax(appScenicSpotService.deleteAppScenicSpotBySpotIds(spotIds));
    }
}
